package com.black.cat.jvm.classfile.constantpool.impl;


import com.black.cat.jvm.classfile.ClassReader;
import com.black.cat.jvm.classfile.constantpool.BaseConstantInfo;
import com.black.cat.jvm.classfile.constantpool.ConstantInfo;
import com.black.cat.jvm.classfile.constantpool.ConstantPool;
import com.black.cat.jvm.common.CommonValue;

/**
 * @Author blackcat
 * @create 2021/8/11 21:40
 * @version: 1.0
 * @description:标识方法类型
 *
 * CONSTANT_MethodType_info {
 * u1 tag;
 * u2 descriptor_index;
 * }
 */
public class ConstantInfoMethodType extends BaseConstantInfo implements ConstantInfo {
    private ConstantPool constantPool;
    private int descriptorIndex; // 方法的描述符索引

    public ConstantInfoMethodType(ConstantPool constantPool, ClassReader reader) {
        this.constantPool = constantPool;
        this.descriptorIndex = reader.nextU2ToInt();
    }

    @Override
    public String getValue() {
        value = constantPool.getUtfStringByIndex(descriptorIndex);
        return super.getValue();
    }

    @Override
    public int getTag() {
        return  CommonValue.CONSTANT_POOL_TAG_METHOD_TYPE;
    }
}
